package com.ywy.dao;

import com.ywy.entity.Message;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * 系统消息Repository接口
 *
 * @author ywy
 * @date 2023/3/25 17:50
 */
public interface MessageDao extends JpaRepository<Message, Integer>, JpaSpecificationExecutor<Message> {
    /**
     * 查询某个用户下的所有消息
     *
     * @param userId
     * @return
     */
    @Query(value = "select count(*) from sys_message where is_see=0 and user_id=?1", nativeQuery = true)
    int getCountByUserId(Integer userId);

    /**
     * 修改成已查看状态
     * @param userId
     * @return
     */
    @Modifying
    @Query(value = "update sys_message set is_see=1 where user_id=?1", nativeQuery = true)
    int updateStatus(Integer userId);
}
